import { $post,$get } from "../utils/request.ts";
import { ElNotification } from "element-plus";
import {md5} from 'md5js'
//登录方法
export const $Login = async (params: object) => {
    //对密码进行加密
    
    // let data = {username:params.username,password:md5((md5(params.password,32).split('').reverse().join()),32)}
    // let ret = await $post('/login', data)
    let ret = {success:true,message:"登陆成功",token:"123asd1243321"}
    if (ret.success) {
        //登陆成功后将token加入浏览器缓存
        //浏览器关闭时清除
        sessionStorage.setItem('token', ret.token)
        ElNotification({
            title: '通知',
            message: ret.message,
            type:'success'
        })
        //浏览器关闭不清除
        //localStorage.setItem('token', ret.token)
        return true
    } else {
        ElNotification({
            title: '通知',
            message: ret.message,
            type:'error'
        })
        return false
    }
}

export const $getOneUser = async (params: object) => {
    let ret = await $get('/getOneUser', params)
    return ret
}